package org.zero.onlinesubject.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.*;
import org.zero.onlinesubject.common.vo.Result;
import org.zero.onlinesubject.common.vo.TaskPubVo;
import org.zero.onlinesubject.entity.TagType;
import org.zero.onlinesubject.entity.TaskDetails;
import org.zero.onlinesubject.entity.TaskPub;
import org.zero.onlinesubject.entity.TaskType;
import org.zero.onlinesubject.service.TagTypeService;
import org.zero.onlinesubject.service.TaskDetailService;
import org.zero.onlinesubject.service.TaskPubService;
import org.zero.onlinesubject.utils.IDWorker;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/task/api")
public class TaskController {

    @Resource
    private TaskPubService pubService;

    @Resource
    private TaskDetailService taskDetailService;

    @Resource
    private TagTypeService tagTypeService;

    @GetMapping("/getBizId")
    public Result<String> createBizID(){
        return Result.ok(IDWorker.createTaskID());
    }

    @GetMapping("/taskTypes")
    public Result<List<TaskType>> getTaskTypes(){
        List<TaskType> taskTypes = pubService.getTaskTypes();
        return Result.ok(taskTypes);
    }

    @GetMapping("/tagTypes")
    public Result<List<TagType>> getTagTypes(){
        return Result.ok(tagTypeService.list());
    }

    @PostMapping("/publish")
    public Result<String> pubTask(@RequestBody TaskPub taskPub){
        Boolean flag = pubService.publishTask(taskPub);
        return flag ? Result.ok("发布任务成功") : Result.error(500,"发布任务失败");
    }

    @PostMapping("/saveDetails")
    public Result<String> saveDetails(@RequestBody TaskDetails taskDetails){
        Boolean flag = pubService.saveTask(taskDetails);
        return flag ? Result.ok("保存任务详情成功") : Result.error(500,"保存任务详情失败");
    }

    @GetMapping("/taskDetails")
    public Result<TaskDetails> getTaskDetails(String taskId){
        TaskDetails details = taskDetailService.getTaskDetail(taskId);
        return Result.ok(details);
    }

    @GetMapping("/getTaskInfo")
    public Result<TaskPubVo> getTaskInfo(String taskId){
        TaskPubVo vo = pubService.getTaskInfo(taskId);

        return Result.ok(vo);
    }
}
